<template>
  <div class="app-container">
    <eHeader :query="query"/>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" height="500">
       <el-table-column prop="customerName" label="所属客户"/>
        <el-table-column prop="account" label="账号"/>
      <el-table-column prop="username" label="姓名"/>
      <!-- <el-table-column prop="password" label="密码"/> -->
      <el-table-column prop="cellphone" label="手机号码"/>
      <!-- <el-table-column prop="customerId" label="所属客户id"/> -->
     
      <el-table-column v-if="checkPermission(['ADMIN','TCUSTOMERUSER_ALL','TCUSTOMERUSER_EDIT','TCUSTOMERUSER_DELETE'])" label="操作" width="220px" align="center">
        <template slot-scope="scope">
          <edit v-permission="['ADMIN','TCUSTOMERUSER_ALL','TCUSTOMERUSER_EDIT']" :data="scope.row" :sup_this="sup_this" :is-view="false"/>
          <edit v-permission="['ADMIN','TCUSTOMERUSER_ALL','TCUSTOMERUSER_EDIT']" :data="scope.row" :sup_this="sup_this" :is-view="true"/>
          <el-popover
            v-permission="['ADMIN','TCUSTOMERUSER_ALL','TCUSTOMERUSER_DELETE']"
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
          </el-popover>
               <el-button  @click="getDeviceInfo(scope.row.id)" type="success" icon="el-icon-check"   size="mini"></el-button>
               <el-dialog :visible.sync="dialog" title="客户所属设备" append-to-body width="800px">
                  <el-table height="250" v-loading="loading" :data="tableData" size="small" style="width: 100%;">
                    <el-table-column label="序号" width="80" align="center">
                      <template slot-scope="scope">
                        <div>{{ scope.$index + 1 }}</div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="eqptname" label="设备名称"/>
                    <el-table-column prop="eqpttypeid" label="设备类型"/>
                    <el-table-column prop="eqptcode" label="设备编号">
                      <!-- <template slot-scope="scope">
                        <el-input v-model="data[scope.$index].columnComment" class="edit-input"/>
                      </template> -->
                    </el-table-column>
                    <!-- <el-table-column label="查询方式">
                      <template slot-scope="scope">
                        <el-select v-model="data[scope.$index].columnQuery" class="edit-input" clearable placeholder="请选择">
                          <el-option
                            label="模糊查询"
                            value="1"/>
                          <el-option
                            label="精确查询"
                            value="2"/>
                        </el-select>
                      </template>
                    </el-table-column> -->
                    <!-- <el-table-column align="center" prop="columnShow" label="列表显示">
                      <template slot-scope="scope">
                        <el-tooltip :content="scope.row.columnShow === 'true' ?'显示':'不显示'" placement="top">
                          <el-switch
                            v-model="data[scope.$index].columnShow"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            active-value="true"
                            inactive-value="false"/>
                        </el-tooltip>
                      </template>
                    </el-table-column> -->
                  </el-table>
                </el-dialog>

         
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
import request from '@/utils/request'
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/tCustomerUser'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
export default {
  components: { eHeader, edit },
  mixins: [initData],
  data() {
    return {
      delLoading: false, sup_this: this,dialog: false,
       tableData:[],
       
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      this.url = 'api/tCustomerUser'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      const type = query.type
      //const value = query.value
      //if (type && value) { this.params[type] = value }
      if (query.cellphone) {
        this.params["cellphone"] = query.cellphone;
      }
      if (query.username) {
        this.params["username"] = query.username;
      }
      
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
    getDeviceInfo(id) {
      debugger;
      this.dialog = true
      this.time = 130
      this.byObjectId(id).then(res => {
         this.tableData=res;
      })
    },
    // 获取id值
    byObjectId(id) {
      return request({
        url: 'api/tEquipment/byCustomerId/' + id,
        method: 'get'
      })
    },
  }
}
</script>

<style scoped>

</style>
